package com.aaa.rent.controller.api;
import com.aaa.entity.Car;
import com.aaa.entity.CarType;
import com.aaa.rent.service.*;
import com.aaa.security.annotation.HasPermission;
import com.aaa.security.annotation.MyLog;
import com.aaa.vo.CarVo;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wys
 * @version 1.0
 * @date 2023/3/1 11:23
 */
@Api(value = "rent/api/CarController", tags = {"api车辆控制"})
@RestController
@RequestMapping("rent/api/CarController")
public class AipCarController {
    @Autowired
    private CarService carService;
    @Autowired
    private CarTypeService carTypeService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private BrandService brandService;
    @Autowired
    private CarTypeConfigDetailsService carTypeConfigDetailsService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Car", name = "car", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @MyLog(title = "添加车辆")
    @RequestMapping("insert")
    public Result insert(@RequestBody Car car){

        return carService.insert(car);}

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Car", name = "car", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @MyLog(title = "更新车辆")
//    @HasPermission(value = "rent:updateCar")
    @RequestMapping("update")
    public Result update(@RequestBody Car car){
        return carService.update(car);}


    //查询车辆类型
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "CarType", name = "carType", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "查询车辆类型", notes = "查询车辆类型")
    @MyLog(title = "查询车辆类型")
//    @HasPermission(value = "rent:selectCarType")
    @RequestMapping("selectType")
    public Result selectType(CarType carType,Integer currentPage,Integer pageSize)
    {return carTypeService.selectCarType(carType,currentPage,pageSize);}

    //查询分店
    @ApiOperation(value = "查询分店", notes = "查询分店")
    @MyLog(title = "查询分店")
//    @HasPermission(value = "rent:selectOtherShop")
    @RequestMapping("selectShop")
    public Result selectShop(){return shopService.selectShop();}

    /**
     * @author JYH
     * @date 2023/3/3 19:11
     * @description - 查询类型
     * @param
     */
    @ApiOperation(value = "- 查询类型", notes = "- 查询类型", httpMethod = "GET")
    @GetMapping("/selectBrand")
    public Result selectBrand(){
        return brandService.selectBrand();
    }

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/selectConfig")
    public Result selectConfig(){
        return carTypeConfigDetailsService.selectConfig();
    }

    /**
     * @author JYH
     * @date 2023/3/4 11:13
     * @description -
     * @param currentPage
     * @param pageSize
     * @param carName
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "carName", value = "", required = true)
    })
    @ApiOperation(value = "-", notes = "-", httpMethod = "POST")
    @MyLog(title = "查询车辆")
    @PostMapping("/selectAllCars")
    public Result selectAllCars(Integer currentPage,Integer pageSize,String carName){
        return carService.selectAllCars(currentPage,pageSize,carName);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @MyLog(title = "删除车辆")
    @GetMapping("/delete")
    public Result delete(Integer id){
        return carService.delete(id);
    }
}
